import get from '@dfeidao/atom-web/local/get';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import { IFeidaoAiBrowserComponent } from '@dfeidao/web/interfaces';

import remove from '@dfeidao/atom-web/local/remove';
import P03 from './P03';
import P04 from './P04';
import P05 from './P05';


export default async function a020(fd: IFeidaoAiBrowserComponent) {
	remove(fd, 'obj');
	const productid = get(fd, 'productid');
	const page_no = get(fd, 'page_no') as number;
	const page_size = get(fd, 'page_size') as number;

	const res = await nodejs<{ dataArray: object[], count: number, page_no: number, page_size: number }>('roler/zj-000001/s001', { productid, page_no, page_size });
	if (res.count === 0) {
		render(fd, '', P03, 'P03', 'inner');
		render(fd, '', P04, 'P04', 'inner');
		fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="P05"]').innerHTML = '';
	} else {
		fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="P04"]').innerHTML = '';
		render(fd, res.dataArray, P03, 'P03', 'inner');
		res.page_no = page_no;
		res.page_size = page_size;
		if (res.count >= page_size) {
			render(fd, res, P05, 'P05', 'inner');
		} else {
			fd.data.node.querySelector<HTMLDivElement>('[data-feidao-presentation="P05"]').innerHTML = '';
		}
	}
}
